﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

namespace IllustratedCsharp7_ch18Generic_Delegate
{
    //Func 接受带有两个形参和一个返回值的方法。方法返回类型被TR标识，方法参数类型被标识为T1,T2。
    public delegate TR Func<T1, T2, TR>(T1 p1, T2 p2);//泛型委托
    class Simple
     {
        static public string PrintString(int p1, int p2) //方法匹配委托
        {
            int total = p1 + p2;
            return total.ToString();
        }
        static public int PrintInt(double d1,double d2) //方法匹配委托
        {
            int total = (int)(d2 + d2);
            return total;
        }
     }
    class Chapt18_8_GenericDelegateOther
    {
        static void _Main()
        {
            var myDel = new Func<int, int, string>(Simple.PrintString);//创建委托实例
            Console.WriteLine($"Total:{myDel(15,13)}");     //调用委托


            var myIntDel = new Func<double, double, int>(Simple.PrintInt);
            Console.WriteLine($"Total:{myIntDel(12.2,13.1)}");     //调用委托

        }

    }
}
